<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>History Demo JavaScript Page</title>
</head>
<body>
<script src="../base.js"></script>
<script>
goog.require('goog.History');
goog.require('goog.debug.DivConsole');
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.history.EventType');
goog.require('goog.log');
</script>
<script>
var logger = goog.log.getLogger('demo');
var logconsole = new goog.debug.DivConsole(top.document.getElementById('log'));
logconsole.setCapturing(true);

var events = goog.object.getValues(goog.history.EventType);
goog.log.info(logger, 'Listening for: ' + events.join(', ') + '.');

var googHist = new goog.History(
    false, 'history_blank.html', top.document.getElementById('hist_state'));
goog.events.listen(googHist, events, function(e) {
  goog.log.info(logger, goog.string.subs('dispatched: %s (token="%s", isNavigation=%s)',
      e.type, e.token, e.isNavigation));
});
goog.events.listen(googHist, goog.History.EventType.NAVIGATE, navCallback);
googHist.setEnabled(true);

function navCallback(e) {
  var output = top.document.getElementById('token_output');
  if (output) {
    var token = (e.token == null) ? 'null' : '\u201C' + e.token + '\u201D';
    goog.dom.setTextContent(output, token);
  }
}
</script>
</body>
</html>
